/**
 * Definition for a binary tree node.
 * function TreeNode(val, left, right) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.left = (left===undefined ? null : left)
 *     this.right = (right===undefined ? null : right)
 * }
 */
/**
 * @param {TreeNode} root
 * @return {number[]}
 */
var postorderTraversal = function (root) {
  let res = [];
  if (root == null) {
    return res;
  }
  let stack = [];
  stack.push(root);
  while (stack.length) {
    let node = stack[stack.length - 1];
    stack.splice(stack.length - 1, 1);
    if (node.left != null) {
      stack.push(node.left);
    }
    if (node.right != null) {
      stack.push(node.right);
    }
    res.push(node.val);
  }
  return res.reverse();
};
let root = [1,null,2,3];
console.log(postorderTraversal(root));
root = [];
console.log(postorderTraversal(root));
